import http from "./http.js"
//引用md5对密码进行加密
import md5 from 'js-md5'

// ======================= 注册接口
// 这样写，在组件中调用接口，就相当于调用方法
export function register(name, pwd) {
    return http.post("/user/register", {
        loginName: name,
        password: pwd
    })
}

// ======================= 登录接口
export function login(name, pwd) {
    return http.post("/user/login", {
        loginName: name,
        passwordMd5: md5(pwd)
    })
}

// ======================= 首页数据
export function getIndexInfo() {
    return http.get("/index-infos")
}

// ======================= 根据商品ID获取详情
export function getInfoData(id) {
    return http.get("/goods/detail/" + id)
}

// ======================= 添加商品到购物车
export function addCart(options) {
    return http.post("/shop-cart", options)
}

// ======================= 获取购物车列表
export function getCartList() {
    return http.get("/shop-cart")
}


// ======================= 删除购物车列表
export function deleteCartList(id) {
    return http.delete('/shop-cart/' + id)
}

// ======================= 步进器列表
export function putCartList(id, gt) {
    return http.put('/shop-cart/', {
        cartItemId: id,
        goodsCount: gt
    })
}

// ======================= 获取地址列表
export function getAddressList() {
    return http.get("/address")
}

// ======================= 根据ID获取某个地址，实现数据回显
export function getAddressDetail(id) {
    return http.get("/address/" + id)
}

// ======================= 编辑地址
export function updateAddress(obj) {
    return http.put("/address", obj)
}

// ======================= 新增地址
export function addAddress(obj) {
    return http.post("/address", obj)
}

// =======================获取生成订单的商品
export function getOrderCard(id) {
    return http.get('/shop-cart/settle?cartItemIds=' + id)
}

// =======================创建订单
export function saveOrder(obj) {
    return http.post("/saveOrder", obj)
}

// =======================支付接口
export function paySuccess(orderNo, type) {
    return http.get("/paySuccess", {
        params: {
            orderNo: orderNo,
            payType: type
        }
    })
}

// ======================= 获取订单列表
export function getOrderList(pageNumber, status = "") {
    // ?pageNumber=1&status=
    return http.get('/order', {
        params: {
            pageNumber: pageNumber,
            status: status
        }
    })
}

// ======================= 获取用户信息
export function getUserInfo() {
    return http.get('/user/info')
}

// ================================================= 其它接口

// ================= 点击确认收货
export function OkOrderDetails(orderNo) {
    return http.put('/order/' + orderNo + '/finish')
}
// ================= 点击取消订单
export function NotOkOrderDetails(orderNo) {
    return http.put('/order/' + orderNo + '/cancel')
}

// ================= 点击订单跳转到确认收货页面拿数据
export function getOrderDetails(id) {
    return http.get('/order/' + id)
}
// ================= 保存更改
export function save(introduceSign, nickName, pwd) {
    return http.put('/user/info', {
        introduceSign: introduceSign,
        nickName: nickName,
        passwordMd5: md5(pwd)
    })
}
// ================= 退出登录
export function infos() {
    return http.get('/index-infos')
}
// ================= 点击搜索
export function search(pn, kw, ob) {
    return http.get('/search', {
        params: {
            pageNumber: pn,
            keyword: kw,
            orderBy: ob
        }
    })
}





